load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//third_party/qt5:qt.bzl", "qt_cc_library")
load("//tools/install:install.bzl", "install")
load("//tools:cpplint.bzl", "cpplint")

package(default_visibility = ["//visibility:public"])

install(
    name = "install",
    targets = [
        ":lidar_imu_calibrator",
    ],
    deps = [
        "//cyber:install",
    ],
)

cc_library(
    name = "imgui",
    srcs = [
        "thirdparty/gl3w/gl3w.c",
        "thirdparty/imgui/imgui.cpp",
        "thirdparty/imgui/imgui_demo.cpp",
        "thirdparty/imgui/imgui_draw.cpp",
        "thirdparty/imgui/imgui_widgets.cpp",
        "thirdparty/imgui/examples/imgui_impl_glfw.cpp",
        "thirdparty/imgui/examples/imgui_impl_opengl3.cpp",
    ],
    hdrs = [
        "thirdparty/gl3w/GL/gl3w.h",
        "thirdparty/imgui/imgui.h",
        "thirdparty/imgui/examples/imgui_impl_glfw.h",
        "thirdparty/imgui/examples/imgui_impl_opengl3.h",
    ],
    copts = [
        "-DIMGUI_IMPL_OPENGL_LOADER_GL3W",
        "-std=c++17",
    ],
    includes = [
        "thirdparty/gl3w",
        "thirdparty/imgui",
    ],
   linkstatic = False,
    deps = [
        "@opengl",
        "@glfw",
    ],
)

cc_library(
    name = "guik",
    srcs = [
        "src/glk/mesh.cpp",
        "src/glk/lines.cpp",
        "src/glk/colormap.cpp",
        "src/glk/glsl_shader.cpp",
        "src/glk/frame_buffer.cpp",
        "src/glk/pointcloud_buffer.cpp",
        "src/glk/primitives/primitives.cpp",
        "src/glk/loaders/ply_loader.cpp",
        "src/guik/gl_canvas.cpp",
        "src/guik/model_control.cpp",
        "src/guik/camera_control.cpp",
        "src/guik/projection_control.cpp",
        "src/guik/imgui_application.cpp",
    ],
    copts = [
        "-std=c++17",
    ],
    includes = [
        "include",
        "thirdparty/imgui",
        "thirdparty/gl3w",
        "thirdparty/imgui/examples",
    ],
    linkstatic = False,
    deps = [
        ":imgui",
        "@opengl",
        "@eigen",
        "@local_config_pcl//:pcl",
    ],
)

cc_library(
    name = "nlopt",
    srcs = [
        "thirdparty/nlopt/lib/libnlopt.so.0",
    ],
    includes = [
        "thirdparty/nlopt/include",
    ],
)

qt_cc_library(
    name = "lidar_imu_calibrator_lib",
    srcs = [
        "src/main.cc",
        "src/lidar_imu_calibrator.cpp",
        "src/self_lidar_imu_calibrator.cpp",
        "src/odometry_frame_set.cpp",
        "src/odometry_frame.cpp",
        "src/compensate_data_dialog.cpp",
        "src/load_data_dialog.cpp",
        "src/record_data.cpp",
        "src/record_data_dialog.cpp",
        "src/save_extrinsic_parameters_dialog.cpp",
        "src/version_modal.cpp"
    ],
    hdrs = glob([
        "include/*.h",
    ]),
    copts = [
        "-std=c++17",
        "-Iexternal/qt",
    ],
    includes = [
        ".",
    ],
    uis = glob([
        "src/*.ui",
    ]),
    linkstatic = False,
    deps = [
        "//cyber",
        "//modules/common/math",
        "//modules/common/util:eigen_defs",
        "//modules/localization/msf/common/io:common_io",
        "//modules/localization/msf/common/util:thread_pool",
        "//modules/localization/msf/common/util:util",
        "//modules/localization/proto:gps_cc_proto",
        "//modules/drivers/proto:pointcloud_cc_proto",
        ":guik",
        ":imgui",
        "@eigen",
        ":nlopt",
        "@qt//:qt_core",
        "@qt//:qt_gui",
        "@qt//:qt_widgets",
        "@opencv//:highgui",
        "@com_github_jbeder_yaml_cpp//:yaml-cpp",
    ],
)


cc_binary(
    name = "lidar_imu_calibrator",
    copts = [
        "-Iexternal/qt",
    ],
    includes = [
        ".",
    ],
    linkopts = [
        "-pthread",
    ],
    deps = [
        ":lidar_imu_calibrator_lib",
        "@fastrtps",
        "@qt//:qt_core",
        "@qt//:qt_gui",
        "@qt//:qt_widgets",
    ],
)

# TODO(all): Disable linter temporarily as the generated ui files should be
# excluded from check. But we should also check the .h and .cc files, if they
# are extracted to their own cc_libraries. See the TODO above.
cpplint()
